package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/22 21:08
 **/
public class Day20_2_Num108_SortedArrayToBST {
    class Solution {
        public TreeNode sortedArrayToBST(int[] nums) {
            return dfs(nums, 0, nums.length-1);
        }
        private TreeNode dfs(int[] nums, int l, int r){
            if(l > r) return null;
            int mid = l + ((r-l)>>1);
            TreeNode cur = new TreeNode(nums[mid]);
            cur.left = dfs(nums, l, mid - 1);
            cur.right = dfs(nums, mid + 1, r);
            return cur;
        }
    }
}